package com.smxy.mall.controller;

import com.alibaba.fastjson.JSONArray;
import com.smxy.mall.annotation.CurrentUser;
import com.smxy.mall.common.Response;
import com.smxy.mall.model.Current;
import com.smxy.mall.model.request.AddressReq;
import com.smxy.mall.service.AddressService;
import com.smxy.mall.utils.Token;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

@Api(tags = "地址管理")
@RestController
@RequestMapping("/address")
public class AddressController {
    @Resource
    private AddressService addressService;

    /**
     * 保存地址
     * @param addressReq
     * @return
     */
    @ApiOperation("保存编辑地址")
    @PostMapping("/save")
    public Object save(AddressReq addressReq, @CurrentUser Current current) {
        return Response.success(addressService.save(addressReq,current));
    }

    @ApiOperation("全部地址列表")
    @GetMapping("/list")
    public Object list() {
        return Response.success(addressService.list());
    }

    @ApiOperation("我的地址列表")
    @GetMapping("/myList")
    public Object myList(@CurrentUser Current current) {
        return Response.success(addressService.findByUserId(current.getUserId()));
    }

    @ApiOperation("地址详情")
    @GetMapping("/detail")
    public Object detail(@RequestParam("id")Integer id){
        return Response.success(addressService.findById(id));
    }
}
